<?php
/**
 *	Server Actions.
 *	@category		cmTools
 *	@package		BugTracker.Action.Administration
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@since			0.1
 *	@version		$Id$
 */
/**
 *	Server Actions.
 *	@category		cmTools
 *	@package		BugTracker.Action.Administration
 *	@extends		CMF_Krypton_Core_DefinitionAction
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@since			0.1
 *	@version		$Id$
 */
class Action_Administration_Server extends CMF_Krypton_Core_DefinitionAction
{
	/**
	 *	Constructor.
	 *	@access		public
	 *	@return		void
	 */
	public function __construct()
	{
		parent::__construct();
		$this->loadLanguage( 'administration.server', 'server' );
		$this->addAction( 'addServer' );
		$this->addAction( 'editServer' );
		$this->addAction( 'removeServer' );
		$action	= new Action_Panel_ProjectSelector();
		$action->performActions();
	}
	
	protected function addServer()
	{
		$request	= CMF_Krypton_Core_Registry::getStatic( "request" );
		$words		= $this->words['server']['msg'];

		try
		{
			$logic		= new Logic_Server();
			$request->set( 'add_server_server_id', $request->get( 'serverId' ) );
			if( !$logic->addServer( $request->getAll(), 'add_server_' ) )
				return $this->messenger->noteError( $words['error_server_not_added'] );
			$this->messenger->noteSuccess( $words['success_server_added'] );
			$request->remove( 'add_server_title' );
			$request->remove( 'add_server_description' );
		}
		catch( Exception $e )
		{
			$this->handleException( $e, 'server', 'addServer' );
		}
	}
	
	protected function editServer()
	{
		$request	= CMF_Krypton_Core_Registry::getStatic( "request" );
		$words		= $this->words['server']['msg'];

		$serverId		= $request->get( 'serverId' );
		if( $serverId )
		{
			try
			{
				$logic	= new Logic_Server();
				if( $logic->editServer( $serverId, $request->getAll(), 'edit_server_' ) )
					$this->messenger->noteSuccess( $words['success_server_edited'] );
				else
					$this->messenger->noteError( $words['error_server_not_edited'] );
				$request->remove( 'serverId' );
			}
			catch( Exception $e )
			{
				$this->handleException( $e, 'server', 'editServer' );
			}
		}		
	}

	protected function removeServer( $serverId)
	{
		try
		{
			Logic_Server::removeServer( $serverId );
		}
		catch( Exception $e )
		{
			$this->handleException( $e );
		}
	}
}
?>